#include<bits/stdc++.h>
using namespace std;
int T;
int n,maxn;
int a[200005];
int b[200005];
int ans[50];
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin >> T;
    for(int x = 1;x <= T;x ++)
    {
        cin >> n;
        for(int i = 1;i <= n;i ++)
        {
            cin >> a[i];
            if(a[i] > maxn)
            {
                maxn = a[i];
            }
            b[a[i]] ++;
        }
        while(maxn > 0)
        {
            if(b[maxn] > 1)
            {
                ans[x] += maxn;
            }
            maxn --;
        }
        maxn = 0;
        for(int i = 0;i <= n;i ++)
        {
            b[i] = 0;
        }
    }
    for(int i = 1;i <= T;i ++)
    {
        cout << ans[i] << endl;
    }
    return 0;
}
